home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / clipper / rlib20.zip / RL_MEMOR.PRG < prev    next >
Text File  |  1989-02-18  |  2KB  |  61 lines

  1. * Function: MEMORIZE
  2. * Author..: Richard Low
  3. * Syntax..: MEMORIZE()
  4. * Returns.: True if successful.
  5. * Notes...: Function to initialize all fields in current record of current
  6. *           database to memory variables of the same name ( preceded by m-> )
  7.  
  8. FUNCTION MEMORIZE
  9. PARAMETERS p_blank, p_first, p_last
  10. PRIVATE f_alias, f_x, f_field
  11.  
  12. *-- if no fields in database or no file is open
  13. IF FCOUNT() = 0
  14.    *-- bomb out
  15.    RETURN .F.
  16. ENDIF
  17.  
  18. *-- see if they want a blank record (if parm is logical true) default = No
  19. p_blank = IF( TYPE('p_blank') = 'L', p_blank, .F. )
  20.  
  21. *-- see if they specified a starting field number, default to 1st field
  22. p_first = IF( TYPE('p_first') = 'N', p_first, 1 )
  23.  
  24. *-- see if they specified an ending field number, default to last field
  25. p_last = IF( TYPE('p_last') = 'N', p_last, FCOUNT() )
  26.  
  27. *-- get the alias name of the current database
  28. f_alias = ALIAS()
  29.  
  30. *-- go thru all fields in database
  31. FOR f_x = p_first TO p_last
  32.    *-- store field name to memvar for macro substitution
  33.    f_field = FIELD(f_x)
  34.  
  35.    *-- must make it public, otherwise it will be released on return
  36.    PUBLIC &f_field
  37.  
  38.    IF p_blank
  39.       *-- create blank filled variable
  40.       f_type = TYPE(f_field)
  41.       DO CASE
  42.          CASE f_type = 'C'
  43.             M->&f_field = SPACE( LEN( &f_alias.->&f_field ) )
  44.          CASE f_type = 'N'
  45.             M->&f_field = 0
  46.          CASE f_type = 'D'
  47.             M->&f_field = CTOD('  /  /  ')
  48.          CASE f_type = 'L'
  49.             M->&f_field = .F.
  50.          CASE f_type = 'M'
  51.             M->&f_field = ''
  52.       ENDCASE
  53.    ELSE
  54.       *-- store field contents to the memvar of same name as field
  55.       M->&f_field = &f_alias.->&f_field
  56.    ENDIF
  57.  
  58. NEXT f_x
  59.  
  60. RETURN .T.
  61.